package com.ss.android.wenda.answer.detail2;

import android.app.Activity;
import android.app.ActivityManager;
import android.app.Dialog;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.bytedance.article.common.c.JSONObjectWrapper;
import com.bytedance.common.utility.Logger;
import com.bytedance.common.utility.UIUtils;
import com.bytedance.common.utility.collection.WeakHandler;
import com.ss.android.account.Spipe;
import com.ss.android.action.ArticleActionHelper;
import com.ss.android.action.a.a.Comment;
import com.ss.android.article.base.app.AppData;
import com.ss.android.article.base.feature.app.schema.AdsAppActivity;
import com.ss.android.article.base.feature.detail.model.ArticleInfo;
import com.ss.android.article.base.feature.detail.model.ArticleDetail;
import com.ss.android.article.base.feature.detail.presenter.ActivityStackManager;
import com.ss.android.article.base.feature.detail.presenter.ActivityStackManager.Type;
import com.ss.android.article.base.feature.detail.presenter.DetailLoader;
import com.ss.android.article.base.feature.detail.presenter.CommentFetcher;
import com.ss.android.article.base.feature.detail.presenter.DetailHelper;
import com.ss.android.article.base.feature.detail2.cc;
import com.ss.android.article.base.feature.detail2.SSPage;
import com.ss.android.article.base.feature.detail2.h;
import com.ss.android.article.base.feature.detail2.widget.DeleteView;
import com.ss.android.article.base.feature.detail2.widget.DetailErrorView;
import com.ss.android.article.base.feature.detail2.widget.DetailTitleBar;
import com.ss.android.article.base.feature.detail2.widget.DetailToolBar;
import com.ss.android.article.base.feature.e.ArticleShareHelper;
import com.ss.android.article.base.feature.feed.presenter.ListData;
import com.ss.android.article.base.feature.model.Article;
import com.ss.android.article.base.feature.model.CellRef;
import com.ss.android.article.base.feature.update.b.UpdateItemMgr;
import com.ss.android.article.base.feature.video.IVideoFullscreen;
import com.ss.android.article.base.utils.ArticleHelper;
import com.ss.android.article.base.utils.a.SharedPreferenceUtils;
import com.ss.android.article.browser.R;
import com.ss.android.article.common.share.helper.CommonHtmlShareHelper;
import com.ss.android.article.common.share.entry.ArticleDetailShareBean;
import com.ss.android.common.app.IComponent;
import com.ss.android.common.lib.MobClickCombiner;
import com.ss.android.common.dialog.AlertDialog;
import com.ss.android.common.ui.view.SwipeOverlayFrameLayout;
import com.ss.android.common.util.ImmersedStatusBarHelper;
import com.ss.android.common.util.NetworkUtils;
import com.ss.android.common.util.ToolUtils;
import com.ss.android.common.util.json.JsonUtil;
import com.ss.android.model.BaseArticle;
import com.ss.android.model.ItemType;
import com.ss.android.model.AbsArticle;
import com.ss.android.newmedia.a.AdsAppBaseActivity;
import com.ss.android.newmedia.activity.BaseActivity;
import com.ss.android.newmedia.e.ShareHelper;
import com.ss.android.newmedia.f.Response;

import org.json.JSONException;
import org.json.JSONObject;

import java.lang.ref.WeakReference;
import java.util.List;

public class NewAnswerDetailActivity extends BaseActivity implements
        WeakHandler.Callback,
        DetailLoader.Callback,
        cc,
        h,
        DetailTitleBar.OnChildViewClickCallback,
        DetailToolBar.OnChildViewClickCallback {
    public static final String a;

    static {
        a = NewAnswerDetailActivity.class.getSimpleName();
    }

    private final WeakHandler G;
    protected Spipe j;
    com.ss.android.wenda.answer.detail2.a b;
    boolean c;
    long d;
    long e;
    long f;
    int g;
    Article h;
    AppData i;
    DetailTitleBar k;
    DetailToolBar l;
    ArticleDetail m;
    DetailErrorView n;
    DetailHelper o;
    private int A;
    private String B;
    private String C;
    private String D;
    private int E;
    private String F;
    private boolean H;
    private String I;
    private DeleteView J;
    private ArticleShareHelper mArticleShareHelper;
    private ShareHelper L;
    private ArticleActionHelper M;
    private SSPage mSSPage;
    private View p;
    private SwipeOverlayFrameLayout q;
    private String r;
    private int s;
    private long t;
    private long u;
    private int v;
    private String w;
    private long x;
    private String y;
    private String z;

    public NewAnswerDetailActivity() {

        this.s = 0;
        this.x = 0;
        this.A = 1;
        this.B = null;
        this.C = null;
        this.D = null;
        this.E = -1;
        this.F = null;
        this.G = new WeakHandler(((WeakHandler.Callback) this));
    }

    static Article a(NewAnswerDetailActivity arg1) {
        return arg1.h;
    }

    public static void a(Context arg1, String arg2) {
        AdsAppBaseActivity.openUrl(arg1, arg2, null);
    }

    static void a(NewAnswerDetailActivity arg5, long arg6, String arg8) {
        CommonHtmlShareHelper v0 = new CommonHtmlShareHelper(((Context) arg5));
        ArticleDetailShareBean v1 = new ArticleDetailShareBean();
        v1.content = arg8;
        v1.itemId = arg6;
        v1.isViewValid = arg5.isViewValid();
        v0.a(arg5.h, new Object[]{v1});
    }

    static void a(NewAnswerDetailActivity arg3, Intent arg4) {
        if (arg4 != null) {
            Uri v0 = arg4.getData();
            ComponentName v1 = arg4.getComponent();
            if (v0 != null && v1 != null) {
                String v0_1 = v0.getHost();
                String v1_1 = v1.getClassName();
                if (!TextUtils.isEmpty(((CharSequence) v0_1)) && !TextUtils.isEmpty(((CharSequence) v1_1)) && (v0_1.equals("wenda_detail")) && (v1_1.equals(AdsAppActivity.class.getName()))) {
                    arg3.finish();
                }
            }
        }
    }

    static DetailToolBar b(NewAnswerDetailActivity arg1) {
        return arg1.l;
    }

    static ArticleDetail c(NewAnswerDetailActivity arg1) {
        return arg1.m;
    }

    static SSPage d(NewAnswerDetailActivity arg1) {
        return arg1.mSSPage;
    }

    public final void onBackClick() {
        if (this.mSSPage == null || (this.H)) {
            this.a("page_close_button");
        } else {
            this.mSSPage.onBackClick();
        }
    }

    public final void onTopMoreTitleClick() {
        this.a("click_more", "detail_top_bar");
        if (this.mSSPage != null && (this.mSSPage.isVisible())) {
            this.mSSPage.onTopMoreTitleClick();
        } else if (this.L != null) {
            this.d(true);
        }
    }

    public final void onCloseAllWebPageClick() {
        if (this.mSSPage != null && (this.mSSPage.isVisible())) {
            this.mSSPage.onUserClickCloseBtn();
        }
    }

    public final void onWechatShareClick() {
        if (this.L != null && this.h != null) {
            this.mArticleShareHelper.position = "detail_top_bar_out";
            this.shareToPlatform(2);
        }
    }

    public final void onQQShareClick() {
        if (this.L != null && this.h != null) {
            this.mArticleShareHelper.position = "detail_top_bar_out";
            this.shareToPlatform(3);
        }
    }

    public final void onMomentShareClick() {
        if (this.L != null && this.h != null) {
            this.mArticleShareHelper.position = "detail_top_bar_out";
            this.shareToPlatform(1);
        }
    }

    public final void onSharePlatformClick() {
        this.mArticleShareHelper.position = "detail_bottom_bar_out";
        SharedPreferenceUtils.inst();
        this.shareToPlatform(SharedPreferenceUtils.getInt("recent_share_way"));
    }

    public final void onInfoBackClick() {
        if (this.mSSPage != null && (this.mSSPage.isVisible())) {
            this.mSSPage.onInfoBackClick();
        }
    }

    public final void onWriteCommentClick() {
        if (this.mSSPage == null || !this.mSSPage.isVisible()) {
            android.support.design.a.showImageToast(((Context) this), R.string.net_unvailable, 0);
        } else {
            this.mSSPage.onWriteCommentClick();
        }
    }

    public final void onFavorBtnClick() {
        int v2;
        long v6 = 0;
        if (this.mSSPage != null && (this.mSSPage.isVisible())) {
            this.mSSPage.onFavorBtnClick();
            return;
        }

        if (this.h != null) {
            String v3 = this.h.userRepin ? "unfavorite_button" : "favorite_button";
            Article v0 = this.h;
            if (v0 != null && ((BaseArticle) v0).groupId > v6) {
                JSONObject v8 = new JSONObject();
                try {
                    v8.put("item_id", ((BaseArticle) v0).itemId);
                    v8.put("aggr_type", ((BaseArticle) v0).aggrType);
                } catch (JSONException v1) {
                }

                MobClickCombiner.onEvent(this, "detail", v3, ((BaseArticle) v0).groupId, v6, v8);
            }

            Article v3_1 = this.h;
            if (v3_1 == null) {
            } else {
                long v4 = this.d;
                boolean v0_1 = !v3_1.userRepin ? true : false;
                v3_1.userRepin = v0_1;
                AppData.isNightMode();
                if (v3_1.userRepin) {
                    this.b(com.ss.android.article.browser.R.string.toast_favor);
                    ++v3_1.repinCount;
                    v2 = 4;
                    ArticleHelper.a = true;
                } else {
                    this.b(com.ss.android.article.browser.R.string.toast_unfavor);
                    --v3_1.repinCount;
                    if (v3_1.repinCount < 0) {
                        v3_1.repinCount = 0;
                    }

                    v2 = 5;
                    ArticleHelper.a = false;
                }

                this.i.a = System.currentTimeMillis();
                List v6_1 = this.j.b();
                if (v3_1.userRepin) {
                    if ((this.i.mShareWhenFavor) && !v6_1.isEmpty()) {
                        this.M.a(v2, ((AbsArticle) v3_1), v4, v6_1);
                    } else {
                        this.M.a(v2, ((AbsArticle) v3_1), v4);
                    }
                } else {
                    this.M.a(v2, ((AbsArticle) v3_1), v4);
                }
            }
        }

        if ((this.i.j()) && this.h != null && (this.h.userRepin) && !this.j.isLogin && (this.i.j())) {
            AlertDialog.Builder v0_2 = com.ss.android.j.b.createDialogBuilder(((Context) this));
            v0_2.setMessage(com.ss.android.article.browser.R.string.ry);
            v0_2.setPositiveButton(com.ss.android.article.browser.R.string.rx, new p(this));
            v0_2.setNegativeButton(com.ss.android.article.browser.R.string.label_cancel, new com.ss.android.wenda.answer.detail2.h(this));
            MobClickCombiner.onEvent(((Context) this), "auth", "login_detail_favor");
            v0_2.setCancelable(true);
            if (this.isViewValid()) {
                v0_2.show();
            }

            this.i.unloginFaverFirst = false;
        }
    }

    public final void onCommentLayoutClick() {
        if (this.mSSPage == null || !this.mSSPage.isVisible()) {
            android.support.design.a.showImageToast(((Context) this), R.string.net_unvailable, 0);
        } else {
            this.mSSPage.onCommentLayoutClick();
        }
    }

    public final void onShare() {
        this.a("detail_share_button", "detail_bottom_bar");
        if (this.mSSPage != null && (this.mSSPage.isVisible())) {
            this.mSSPage.onShare();
        } else if (this.L != null) {
            if (this.i.getAbSettings().isQQTopShare()) {
                this.d(true);
            } else {
                this.d(false);
            }
        }
    }

    private void a(String arg7, String arg8) {
        if (!android.support.design.a.isTextEmpty(arg7)) {
            long v0 = 0;
            if (this.h != null) {
                v0 = this.h.groupId;
            }

            JSONObject v3 = this.b();
            String v2 = v3.optString("source");
            if (v2.equals("headline")) {
                v2 = "click_headline";
            } else if (v2.equals(this.w)) {
                v2 = "click_category";
            } else {
                v2 = "click_" + v2;
            }

            try {
                v3.put("group_id", v0);
                v3.put("position", arg8);
                v3.put("share_platform", null);
                v3.put("enter_from", v2);
                v3.put("category_name", this.w);
                if (this.h != null) {
                    v3.put("user_id", this.h.getUserId());
                }

                if (!AppData.getInstance().getAbSettings().isApplogStaging()) {
                } else {
                    v3.put("_staging_flag", 1);
                }
            } catch (JSONException v0_1) {
            }

            android.support.design.a.onEvent(arg7, v3);
        }
    }

    private boolean a() {
        long v8 = 0;
        Bundle v0 = this.getIntent().getExtras();
        if (v0 == null) {
            boolean v0_1 = false;
            return v0_1;
        }

        v0.getBoolean("bundle_no_hw_acceleration", false);
        v0.getBoolean("from_notification", false);
        this.B = v0.getString("gd_ext_json");
        this.D = v0.getString("api_param");
        if (!android.support.design.a.isTextEmpty(this.B)) {
            try {
                JSONObject v3_1 = new JSONObject(this.B);
                this.y = v3_1.optString("source");
                this.z = v3_1.optString("query");
                this.x = v3_1.optLong("search_result_id");
            } catch (JSONException v3) {
            }
        }

        this.w = v0.getString("category");
        this.C = JsonUtil.a(this.B, "enter_from");
        this.D = android.support.design.a.a(this.D, this.C, "answer_detail");
        v0.getBoolean("view_comments", false);
        v0.getBoolean("is_jump_comment", false);
        v0.getBoolean("show_write_comment_dialog", false);
        if (v0.containsKey("detail_source")) {
            v0.getString("detail_source");
        }

        if (v0.containsKey("stay_tt")) {
            this.A = v0.getInt("stay_tt");
            if (this.A == 0) {
                this.E = v0.getInt("previous_task_id");
                this.F = v0.getString("previous_task_intent");
            }
        }

        v0.getBoolean("is_ugc_style");
        this.c = v0.getBoolean("view_single_id", false);
        this.I = this.getString(com.ss.android.article.browser.R.string.info_article_deleted);
        if (this.c) {
            this.e = v0.getLong("group_id", v8);
            this.f = v0.getLong("item_id", v8);
            this.g = v0.getInt("aggr_type", 0);
            this.t = v0.getLong("flags", v8);
            if (this.t == v8) {
                this.s = v0.getInt("group_flags", 0);
                v0.getInt("article_type", -1);
            } else if ((this.t & 262144) > v8) {
                this.s |= 262144;
            }

            if (this.e <= v8) {
                return false;
            }

            this.u = v0.getLong("from_gid", v8);
            this.d = v0.getLong("ad_id", v8);
            if (this.d > v8) {
                this.r = v0.getString("bundle_download_app_extra");
            }

            String v0_2 = Article.a(this.e, this.f);
            if (this.f <= v8) {
                return true;
            }

            this.h = this.i.e(v0_2);
        } else {
            this.v = v0.getInt("list_type", 0);
            if (this.v == 1 && (android.support.design.a.isTextEmpty(this.w))) {
                return false;
            }

            ListData v0_3 = this.i.a(this.v, this.w);
            if (v0_3 == null) {
                return false;
            }

            List v4 = v0_3.a;
            if (v4 != null && !v4.isEmpty()) {
                int v0_4 = v0_3.b;
                if (v0_4 >= 0 && v0_4 < v4.size()) {
                    Object v0_5 = v4.get(v0_4);
                    if (v0_5 != null && (((CellRef) v0_5).a()) && ((CellRef) v0_5).article != null) {
                        this.d = ((CellRef) v0_5).adId;
                        this.h = ((CellRef) v0_5).article;
                        if (this.h != null) {
                            this.h.ah = ((CellRef) v0_5).isSubscribe;
                        }

                        this.e = this.h.groupId;
                        this.f = this.h.itemId;
                        this.g = this.h.aggrType;
                        this.s = this.h.groupFlags;
                        if (this.d <= v8) {
                        } else {
                            this.r = ((CellRef) v0_5).logExtra;
                        }
                    }
                }

                if (this.h != null) {
                    return true;
                }

                return false;
            }

            return false;
        }

        return true;
    }

    public final void a(String arg7) {
        Object v0_3;
        Object v3 = null;
        int v2 = 0;
        MobClickCombiner.onEvent(((Context) this), "detail", arg7);
        if (!this.c) {
            this.setResult(-1, new Intent());
            this.finish();
            return;
        }

        int v0 = this.A == 0 ? 1 : 0;
        Intent v4 = !this.isTaskRoot() || v0 != 0 ? ((Intent) v3) : ToolUtils.getLaunchIntentForPackage(((Context) this), this.getPackageName());
        if (v4 != null) {
            this.finish();
            if (this.i != null) {
                System.currentTimeMillis();
                AppData.ah();
            }

            v4.putExtra("quick_launch", true);
            this.startActivity(v4);
            return;
        }

        if (v0 != 0 && this.E > 0 && !android.support.design.a.isTextEmpty(this.F)) {
            try {
                List v0_2 = ((ActivityManager) this.getSystemService(Context.ACTIVITY_SERVICE)).getRecentTasks(2, 2);
                if (v0_2 == null) {
                    v0_3 = v3;
                } else if (v0_2.size() > 1) {
                    v0_3 = v0_2.get(1);
                } else {
                    v0_3 = v3;
                }
                if (v0_3 == null) {
                } else if (((ActivityManager.RecentTaskInfo) v0_3).id != this.E) {
                } else {

                    this.finish();
                    this.startActivity(Intent.parseUri(this.F, 1));
                    v2 = 1;
                }
            } catch (Exception v0_1) {
            }
        }

        if (v2 != 0) {
        } else {
            this.finish();
        }
    }

    public final void a(int arg2) {
        if (arg2 >= 0 && this.l != null) {
            this.l.saveShareWay(arg2);
        }
    }

    public final void a(Comment comment) {
        if (this.mSSPage != null && (this.mSSPage.isVisible())) {
            this.mSSPage.a(comment);
        }
    }

    public final void onCommentLoaded(CommentFetcher arg1, boolean arg2) {
    }

    public final void onArticleInfoLoaded(Article article, ArticleInfo articleInfo) {
    }

    public final void onArticleDetailLoadedWithCache(Article article, ArticleDetail articleDetail) {
    }

    public final void onLoaded(Article article, AbsArticle absArticle, ArticleDetail articleDetail) {
        String v1;
        String v0 = null;
        if (!this.isFinishing()) {
            if (articleDetail != null) {
                this.m = articleDetail;
                v1 = articleDetail.content;
                if (articleDetail.delete) {
                    this.b(article);
                    return;
                } else {
                    if (article == null && articleDetail.article != null && articleDetail.article.articleType == 1) {
                        v0 = articleDetail.article.articleUrl;
                    }

                    if (this.h != null) {
                    } else if (articleDetail.article == null) {
                    } else {
                        this.h = articleDetail.article;
                        this.s = this.h.groupFlags;
                    }
                }
            } else {
                v1 = v0;
            }

            int v0_1 = !android.support.design.a.isTextEmpty(v1) || !android.support.design.a.isTextEmpty(v0) ? 0 : 1;
            if (v0_1 == 0 || !NetworkUtils.isNetworkAvailable(((Context) this))) {
                this.d();
            } else {
                this.b.a(absArticle.getItemKey(), article, absArticle);
            }

            if (this.m == null) {
                return;
            }

            if (this.m.spipeUser == null) {
                return;
            }

            if (this.m.spipeUser.mUserId != this.j.userId) {
                return;
            }

            SharedPreferenceUtils.inst();
            if (!SharedPreferenceUtils.getBoolean("first_write_answer")) {
                return;
            }

            this.c();
        }
    }

    public final void a(IVideoFullscreen videoFullscreen) {
    }

    public final void onLoaded(String arg1, long arg2, Response response) {
    }

    public final void onArticleDetailLoadedFromInternet(String arg5, Article article, ArticleDetail articleDetail) {
        if (!this.isFinishing()) {
            if (articleDetail != null) {
                this.m = articleDetail;
                if (this.h == null && articleDetail.article != null) {
                    this.h = articleDetail.article;
                    this.s = this.h.groupFlags;
                }
            }

            if (this.h == null || !NetworkUtils.isNetworkAvailable(((Context) this))) {
                this.n.showNoDataUI(false);
            } else {
                this.d();
            }

            if (this.m == null) {
                return;
            }

            if (this.m.spipeUser == null) {
                return;
            }

            if (this.m.spipeUser.mUserId != this.j.userId) {
                return;
            }

            SharedPreferenceUtils.inst();
            if (!SharedPreferenceUtils.getBoolean("first_write_answer")) {
                return;
            }

            this.c();
        }
    }

    public final void a(boolean arg2) {
        this.l.setWriteCommentEnabled(arg2);
    }

    public final boolean a(Article article) {
        return false;
    }

    public final boolean a(Article article, int arg3) {
        return false;
    }

    private JSONObject b() {
        JSONObject v0 = null;
        try {
            if (android.support.design.a.isTextEmpty(this.B)) {
            } else {
                v0 = new JSONObject(this.B);
            }
            if (v0 == null) {
                v0 = new JSONObject();
            }
            if (this.u > 0) {
                v0.put("from_gid", this.u);
            }

            if (this.w != null) {
                v0.put("category_name", this.w);
            }

            if (this.h == null) {
                return v0;
            }

            v0.put("user_id", this.h.getUserId());
        } catch (JSONException v1) {
        }
        return v0;
    }

    private void b(int arg2) {
        if (!this.isFinishing()) {
            android.support.design.a.showImageToast(((Context) this), arg2, R.drawable.doneicon_popup_textpage);
        }
    }

    public final void b(Article arg5) {
        this.H = true;
        this.J.setVisibility(View.VISIBLE);
        this.k.setTitleBarStyle(3);
        this.k.init();
        this.k.clearAnimation();
        UIUtils.setVisibility(this.k, 0);
        this.c(false);
        Fragment v0 = this.getSupportFragmentManager().findFragmentById(com.ss.android.article.browser.R.id.frame);
        if (v0 != null) {
            FragmentTransaction v1 = this.getSupportFragmentManager().beginTransaction();
            v1.remove(v0);
            v1.commit();
        }

        this.mSSPage = null;
        if (arg5 != null) {
            arg5.delete = true;
            arg5.title = this.I;
            arg5._abstract = "";
            arg5.commentCount = 0;
        }

        if (arg5 != null) {
            UpdateItemMgr.getInstance(((Context) this)).e(arg5.groupId);
        }
    }

    public final void b(boolean arg2) {
        this.l.setFavorIconSelected(arg2);
    }

    private void c() {
        final DetailTitleBar v0 = this.k;
        Context v1 = v0.mTopMoreTitleTv.getContext();
        v0.h = LayoutInflater.from(v1).inflate(com.ss.android.article.browser.R.layout.gb, null);
        PopupWindow v2 = new PopupWindow(v0.h, -2, -2, false);
        v2.setBackgroundDrawable(new ColorDrawable(0));
        v2.setOutsideTouchable(false);
        TextView v3 = v0.mTopMoreTitleTv;
        int[] v4 = new int[2];
        ((View) v3).getLocationOnScreen(v4);
        v2.showAtLocation(((View) v3), 0, v4[0] + ((View) v3).getWidth() / 2, (((int) UIUtils.dp2px(v1, 2f))) + (v4[1] + ((View) v3).getHeight() / 2));
        v0.h.postDelayed(v0.j, 10000);
        v0.h.setOnClickListener(new View.OnClickListener() {

            public final void onClick(View arg5) {
                int v1 = 1;
                if (v0.h != null) {
                    v0.h.removeCallbacks(v0.j);
                }

                int v00 = v0.i != null ? 1 : 0;
                if (v0.i.get() == null) {
                    v1 = 0;
                }

                if ((v00 & v1) != 0) {
                    ((PopupWindow) v0.i.get()).dismiss();
                    v0.i.clear();
                }
            }
        });
        v0.i = new WeakReference(v2);
        SharedPreferenceUtils.inst();
        SharedPreferences.Editor v0_1 = SharedPreferenceUtils.getSharedPreference(null).edit();
        v0_1.putBoolean("first_write_answer", false);
        v0_1.commit();
    }

    private void shareToPlatform(int arg3) {
        if (arg3 >= 0 && this.mArticleShareHelper != null) {
            this.mArticleShareHelper.share(arg3, this.h);
        }
    }

    public final void c(boolean arg3) {
        this.l.clearAnimation();
        DetailToolBar v1 = this.l;
        int v0 = arg3 ? 0 : 8;
        UIUtils.setVisibility(((View) v1), v0);
    }

    private void d() {
        NewAnswerDetailFragment v1_1;
        int v6 = R.id.frame;
        if (!this.isFinishing() && !this.isDestroyed()) {
            int v0 = this.m == null || (TextUtils.isEmpty(this.m.content)) ? 1 : 0;
            if (v0 != 0) {
                this.n.showNoDataUI(false);
                return;
            }

            this.n.hideSelf();
            this.c(true);
            Fragment v1 = this.getSupportFragmentManager().findFragmentById(v6);
            if (v1 == null || !(v1 instanceof SSPage)) {
                v1 = new NewAnswerDetailFragment();
                Intent v0_1 = this.getIntent();
                if (v0_1 != null) {
                    v0_1.putExtra("ad_id", this.d);
                    v0_1.putExtra("bundle_download_app_extra", this.r);
                    v0_1.putExtra("group_id", this.e);
                    v0_1.putExtra("item_id", this.f);
                    ((Fragment) v1).setArguments(v0_1.getExtras());
                }
            }

            this.mSSPage = (SSPage) v1;
            FragmentTransaction v0_2 = this.getSupportFragmentManager().beginTransaction();
            v0_2.replace(v6, v1);
            v0_2.commitAllowingStateLoss();
        }
    }

    private void d(boolean arg6) {
        ArticleInfo v4 = null;
        if (this.mArticleShareHelper != null && this.h != null) {
            if (arg6) {
                switch (this.getCommentMode()) {
                    case 1:
                    case 2: {
                        this.mArticleShareHelper.mCategoryName = this.w;
                        this.mArticleShareHelper.c(this.h, v4, this.d);
                        return;
                    }
                    default: {
                        if (!this.h.m() && !this.h.n()) {
                            this.mArticleShareHelper.b(this.h, v4, this.d);
                            return;
                        }

                        this.mArticleShareHelper.a(this.h, v4, this.d);
                        return;
                    }
                }
            } else {
                this.mArticleShareHelper.mCategoryName = this.w;
                this.mArticleShareHelper.a(this.h, this.d, true);
                return;
            }
        }
    }

    public final AbsArticle getArticle() {
        AbsArticle v0;
        if (this.mSSPage == null || !this.mSSPage.isVisible()) {
            v0 = this.h;
        } else {
            v0 = this.mSSPage.getArticle();
        }

        return v0;
    }

    public final long getArticleId() {
        long v0 = this.mSSPage == null || !this.mSSPage.isVisible() ? 0 : this.mSSPage.getArticleId();
        return v0;
    }

    public ImmersedStatusBarHelper.ImmersedStatusBarConfig getImmersedStatusBarConfig() {
        return new ImmersedStatusBarHelper.ImmersedStatusBarConfig().setStatusBarColor(com.ss.android.article.browser.R.color.status_bar_color_detail);
    }

    public final int getCommentMode() {
        int v0;
        if (this.mSSPage != null && (this.mSSPage.isVisible())) {
            v0 = this.mSSPage.getCommentMode();
        } else if (this.h == null) {
            v0 = 0;
        } else {
            v0 = this.h.getCommentMode();
        }

        return v0;
    }

    public void handleMsg(Message message) {
    }

    public final int i() {
        int v0 = this.mSSPage == null || !this.mSSPage.isVisible() ? 0 : this.mSSPage.i();
        return v0;
    }

    public final long j() {
        long v0 = this.mSSPage == null || !this.mSSPage.isVisible() ? 0 : this.mSSPage.j();
        return v0;
    }

    public final int k() {
        return 0;
    }

    public final String l() {
        return "answer_detail";
    }

    public void onAddressEditClicked(View arg10) {
        String v3;
        int v0;
        if (!Logger.debug()) {
            if (this.i != null && (this.i.aD())) {
                v0 = 1;
            } else {
                v0 = 0;
            }
        } else {
            label_9:
            v0 = 1;
        }

        if (v0 != 0) {
            Dialog v6 = new Dialog(((Context) this), R.style.address_bar_dialog);
            View v7 = LayoutInflater.from(((Context) this)).inflate(com.ss.android.article.browser.R.layout.addr_edit_dialog, null);
            View v8 = v7.findViewById(com.ss.android.article.browser.R.id.address_layout);
            View v0_1 = v7.findViewById(com.ss.android.article.browser.R.id.address_edit);
            View v1 = v7.findViewById(com.ss.android.article.browser.R.id.address_stop_btn);
            View v2 = v7.findViewById(com.ss.android.article.browser.R.id.addr_bar_cancel);
            if (this.h == null) {
                v3 = "";
            } else if (!TextUtils.isEmpty(this.h.displayUrl)) {
                v3 = this.h.displayUrl;
            } else if (!TextUtils.isEmpty(this.h.url)) {
                v3 = this.h.url;
            } else {
                v3 = this.h.articleUrl;
            }

            if (v3 == null) {
                v3 = "";
            }

            v3 = String.valueOf(v3);
            ((EditText) v0_1).setText(((CharSequence) v3));
            ((EditText) v0_1).selectAll();
            ((EditText) v0_1).setSelection(v3.length());
            AppData.isNightMode();
            v7.setBackgroundResource(com.ss.android.article.browser.R.drawable.detail_bg_titlebar);
            UIUtils.setBackgroundResource(v8, R.drawable.detail_titlebar_edit_bg);
            ((EditText) v0_1).setTextColor(this.getResources().getColor(com.ss.android.article.browser.R.color.detail_title_bar_url));
            ((ImageView) v1).setImageResource(com.ss.android.article.browser.R.drawable.titlebar_refresh_detail_cancel);
            ((TextView) v2).setCompoundDrawablesWithIntrinsicBounds(com.ss.android.article.browser.R.drawable.btn_back, 0, 0, 0);
            ((EditText) v0_1).setOnEditorActionListener(new m(this, ((EditText) v0_1), v6));
            ((ImageView) v1).setOnClickListener(new n(((EditText) v0_1)));
            ((TextView) v2).setOnClickListener(new com.ss.android.wenda.answer.detail2.o(this, v6));
            v6.getWindow().setGravity(48);
            v6.getWindow().setLayout(-1, -2);
            v6.getWindow().setSoftInputMode(5);
            v6.setContentView(v7);
            v6.setCanceledOnTouchOutside(true);
            v6.show();
        }
    }

    public void onBackPressed() {
        if (this.mSSPage == null || (this.H)) {
            this.a("page_close_key");
        } else {
            this.mSSPage.onBack();
        }
    }

    public void onCreate(Bundle savedInstanceState) {
        JSONObject v3_2;
        JSONObject v10;
        String v4;
        int v2;
        String v3;
        int v0_1;
        this.requestDisableOptimizeViewHierarchy();
        if (Build.VERSION.SDK_INT >= 17) {
            this.getWindow().addFlags(16777216);
        }

        this.supportRequestWindowFeature(10);
        super.onCreate(savedInstanceState);
        this.setContentView(com.ss.android.article.browser.R.layout.answer_detail_activity2);
        this.i = AppData.getInstance();
        this.j = Spipe.inst();
        this.p = this.findViewById(com.ss.android.article.browser.R.id.root);
        AppData.isNightMode();
        this.p.setBackgroundResource(com.ss.android.article.browser.R.color.c);
        this.k = (DetailTitleBar) this.findViewById(R.id.title_bar);
        this.k.setOnChildViewClickCallback(((DetailTitleBar.OnChildViewClickCallback) this));
        this.l = (DetailToolBar) this.findViewById(R.id.tool_bar);
        this.l.setOnChildViewClickCallback(((DetailToolBar.OnChildViewClickCallback) this));
        this.J = (DeleteView) this.findViewById(R.id.delete_layout);
        this.J.setVisibility(View.GONE);
        this.n = (DetailErrorView) this.findViewById(R.id.detail_error_view);
        this.n.setOnRetryClickListener(new com.ss.android.wenda.answer.detail2.j(this));
        this.q = (SwipeOverlayFrameLayout) this.findViewById(R.id.swipe_overlay_activity);
        this.q.setOnSwipeListener(new k(this));
        if (!this.a()) {
            this.finish();
            return;
        }

        com.ss.android.wenda.answer.detail2.g v6 = new com.ss.android.wenda.answer.detail2.g(this);
        this.M = new ArticleActionHelper(((Context) this));
        this.L = new ShareHelper(((Context) this), ((IComponent) this), this.i);
        this.o = new DetailHelper(this, ItemType.ARTICLE, this.G, this.M, "detail");
        this.o.a();
        this.mArticleShareHelper = new ArticleShareHelper(this, this.M, this.o, 200, true);
        this.mArticleShareHelper.h = new com.ss.android.wenda.answer.detail2.i(this);
        this.mArticleShareHelper.g = ((com.ss.android.article.share.e.b) v6);
        this.mArticleShareHelper.mExtJsonObj = this.b();
        this.mArticleShareHelper.mCategoryName = this.w;
        ArticleShareHelper v1 = this.mArticleShareHelper;
        String v0 = this.h != null ? this.h.groupId + "" : "answer_detail";
        v1.detailSource = v0;
        MobClickCombiner.onEvent(((Context) this), "detail", "enter");
        long v8 = this.d;
        BaseArticle v1_1 = new BaseArticle(this.e, this.f, this.g);
        JSONObject v13 = this.b();
        if (v13 != null) {
            v0_1 = this.h == null || this.h.zzcomment == null || (this.h.zzcomment.isEmpty()) ? 0 : 1;
            try {
                v3 = "has_zz_comment";
                if (v0_1 != 0) {
                    v2 = 1;
                } else {
                    v2 = 0;
                }
                v13.put(v3, v2);
                if (v0_1 == 0) {
                } else {
                    v13.put("mid", this.h.zzcomment.get(0).mediaId);
                }
            } catch (JSONException v0_2) {
                v0_2.printStackTrace();
            }
        }

        if (AppData.getInstance().getAbSettings().isAppLogOld()) {
            v4 = "go_detail";
            String v5 = this.C;
            if (android.support.design.a.isTextEmpty(v4)) {
            } else {
                long v2_1 = v1_1.itemId;
                v0_1 = v1_1.aggrType;
                if (v13 == null) {
                    v10 = new JSONObject();
                } else {
                    v10 = v13;
                }

                try {
                    if (!v10.has("item_id")) {
                        v10.put("item_id", v2_1);
                    }

                    if (v10.has("aggr_type")) {
                    } else {
                        v10.put("aggr_type", v0_1);
                    }
                } catch (Exception v0_3) {
                }

                label_164:
                MobClickCombiner.onEvent(this, v4, v5, v1_1.groupId, v8, v10);
            }
        }

        if (AppData.getInstance().getAbSettings().isAppLogNew()) {
            v4 = "go_detail";
            String v2_2 = this.C;
            if (android.support.design.a.isTextEmpty(v4)) {
            } else {
                v0 = this.w;
                if (!android.support.design.a.isTextEmpty(v2_2)) {
                    if (v2_2.equals("click_" + this.w)) {
                        v2_2 = "click_category";
                        v0 = this.w;
                    } else if (v2_2.equals("click_headline")) {
                        v0 = this.w;
                    } else {
                        v0 = v2_2.replaceFirst("click_", "");
                    }
                }

                long v6_1 = v1_1.itemId;
                int v5_1 = v1_1.aggrType;
                if (v13 == null) {
                    v3_2 = new JSONObject();
                } else {
                    v3_2 = v13;
                }

                try {
                    if (!v3_2.has("item_id")) {
                        v3_2.put("item_id", v6_1);
                    }

                    if (v3_2.has("aggr_type")) {
                    } else {
                        v3_2.put("aggr_type", v5_1);
                    }
                } catch (Exception v5_2) {
                }

                JSONObjectWrapper v0_4 = new JSONObjectWrapper().put("enter_from", v2_2).put("category_name", v0).put("ad_id", Long.valueOf(v8)).put(v3_2).put("group_id", Long.valueOf(v1_1.groupId));
                if (AppData.getInstance().getAbSettings().isApplogStaging()) {
                    v0_4.put("_staging_flag", Integer.valueOf(1));
                }

                if (this.x != 0) {
                    v0_4.put("search_result_id", Long.valueOf(this.x)).put("source", this.y).put("query", this.z);
                }

                android.support.design.a.onEvent(v4, v0_4.jo);
            }
        }

        if (this.h != null) {
            this.b(this.h.userRepin);
        } else {
            this.c(false);
        }

        this.k.b();
        this.n.showLoadingView();
        this.b = new com.ss.android.wenda.answer.detail2.a(this, this.G, this.C, this.D, this.B);
        if (this.c) {
            this.b.b(Article.a(this.e, this.f), null, new Article(this.e, this.f, this.g));
        } else {
            this.b.b(this.h.getItemKey(), this.h, this.h);
        }

        ActivityStackManager.addActivity(Type.WENDA_ACTIVITY, ((Activity) this));
    }

    public void onDestroy() {
        super.onDestroy();
        if (this.k != null) {
            this.k.f();
        }
    }

    public void onResume() {
        super.onResume();
        this.k.g();
    }

    public void startActivityForResult(Intent arg5, int arg6) {
        super.startActivityForResult(arg5, arg6);
        this.p.postDelayed(new com.ss.android.wenda.answer.detail2.l(this, arg5), 1000);
    }
}

